package org.real.guetshop.mapper;

import org.apache.ibatis.annotations.*;
import org.real.guetshop.pojo.dto.EditProductDTO;
import org.real.guetshop.pojo.entity.OrderGood;
import org.real.guetshop.pojo.entity.ShopCart;

import java.util.List;

@Mapper
public interface ShopCartMapper {

    /**
     * 动态查询
     * @param shopCart
     * @return
     */
    List<ShopCart> list(ShopCart shopCart);

    /**
     * 增加商品数量
     * @param cart
     */
    @Update("update shoppingcart set number = #{number} where id = #{id}")
    void updateNumberById(ShopCart cart);

    /**
     *插入购物车数据
     * @param shopCart
     */
    @Insert("insert into shoppingcart(name, image, unit, user_id,store_id, product_id, amount, create_time) " +
            "values (#{name},#{image},#{unit},#{userId},#{storeId},#{productId},#{amount},#{createTime}) ")
    void insert(ShopCart shopCart);

    /**
     * 清空购物车
     * @param userId
     */
    @Delete("delete from shoppingcart where user_id = #{userId}")
    void clean(Integer userId);

    /**
     * 将购物车中的数据转移到订单货物表中
     * @param orderGoods
     */
    void translate(List<OrderGood> orderGoods);

    /**
     * 修改商品数量
     *
     * @param editProductDTO
     * @return
     */
//    @Update("update shoppingcart set number = #{number},amount = #{amount} where product_id = #{productId} and store_id = #{storeId}")
    Boolean editById(EditProductDTO editProductDTO);

    /**
     * 查看购物车商品目前数量
     * @param editProductDTO
     * @return
     */
    @Select("select number from guetshop.shoppingcart where product_id = #{productId} and store_id = #{storeId} and user_id = #{userId}")
    int getNumber(EditProductDTO editProductDTO);

    /**
     * 数量为0，删除该条数据
     * @param editProductDTO
     */
    @Delete("delete from shoppingcart where product_id = #{productId} and store_id = #{storeId} and user_id = #{userId}")
    void deleteById(EditProductDTO editProductDTO);
}
